from threading import Timer
import time


def interval_task(interval, *args):
    # 1. 执行任务逻辑

    # 2. 递归创建新的定时器，实现循环调用
    Timer(interval, interval_task, args=(interval, *args)).start()


class MyDownLoadIterator:
    def __init__(self, percent):
        self.percent = percent

    def __iter__(self):
        return self

    def __next__(self):

        if self.percent >= 100:
            raise StopIteration

        else:
            self.percent += 10

        return self.percent


my_download_iterator = MyDownLoadIterator(0)


percent = 0
# interval_task(100, percent)
for i in range(11):
    time.sleep(1)
    try:
        percent = my_download_iterator.__next__()
        print(f"下载进度：{percent}%")
    except StopIteration as e:
        print("下载完成")
